package com.scenery.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.scenery.R;

import com.scenery.vo.City;
import com.scenery.vo.Scenery;
/***
 * 
 * 景点adapter
 * **/
public class SceneryAdapter extends ArrayAdapter<Scenery> {
	private LayoutInflater inflater;

	protected ArrayList<Scenery> items;

	public SceneryAdapter(Context context, int layout, ArrayList<Scenery> items) {

		// TODO Auto-generated constructor stub
		super(context, layout, items);
		inflater = LayoutInflater.from(context);
		this.items = items;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public synchronized void clear() {
		items.clear();
		notifyDataSetChanged();
	}

	@Override
	public synchronized void add(Scenery bean) {
		items.add(bean);
	}

	public synchronized void modify(int index, Scenery bean) {
		items.set(index, bean);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.scenery_list_item, null);

			holder = new ViewHolder();

			holder.name = (TextView) convertView.findViewById(R.id.sceneryName);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		Scenery bean = items.get(position);
		if (bean != null) {

			holder.name.setText(position + 1 + ". " + bean.getSceneryName());

		}
		return convertView;
	}

	private static class ViewHolder {
		TextView name;

	}
}
